/*
* @Author: Marte
* @Date:   2018-11-01 10:03:30
* @Last Modified by:   Marte
* @Last Modified time: 2018-11-01 10:03:33
*/
const StaffDao = require("../dao/staff/staff_dao.js")

const StaffService={
	add(req,res,next){
		const {name,department,profession,sex,birthday,nativeplace,education,specialty,entercompanytime,salary}=req.body;
		console.log(req.body);
		console.log({name,department,profession,sex,birthday,nativeplace,education,specialty,entercompanytime,salary});
		StaffDao.save({name,department,profession,sex,birthday,nativeplace,education,specialty,entercompanytime,salary})
										.then((data)=>{
											res.json({
												res_code:1,
												res_error:"",
												res_body:{
													status:1,
													data:data
												}
											});
										})
							.catch((err) => {
								res.json({
									res_code: 0,
									res_error: err,
									res_body: {}
								})
							});
	},
	findByPage(req, res, next) {

		const {page} = req.query;
		console.log({page});
		StaffDao.findByPage(page)
							.then((data) => {
								res.json({
									res_code: 1,
									res_error: "",
									res_body: {
										status: 1,
										list: data
									}
								});
							})
							.catch((err) => {
								res.json({
									res_code: 0,
									res_error: err,
									res_body: {}
								});
							});
	},
	find(req, res, next) {

		const {name} = req.query;
		console.log({name});
		StaffDao.find({name})
							.then((data) => {
								res.json({
									res_code: 1,
									res_error: "",
									res_body: {
										status: 1,
										list: data
									}
								});
							})
							.catch((err) => {
								res.json({
									res_code: 0,
									res_error: err,
									res_body: {}
								});
							});
	},	
	removeById(req,res,next){
		const {id} = req.query;
		console.log(id);
		StaffDao.removeById(id)
							.then((data)=>{
								res.json({
									res_code: 1,
									res_error: "",
									res_body: {
										status: 1,
									}
								});								
								
							})
							.catch((err)=>{
								res.json({
									res_code: 0,
									res_error: err,
									res_body: {}
								});								
							});
		
	},
	update(req,res,next){
		const {id} = req.body;
		
		const {name,department,profession,sex,birthday,nativeplace,education,specialty,entercompanytime,salary} = req.body;
		
		StaffDao.update(id,{name,department,profession,sex,birthday,nativeplace,education,specialty,entercompanytime,salary})
							.then((data)=>{
								res.json({
									res_code: 1,
									res_error: "",
									res_body: {
										status: 1,
										data:data
									}
								});								
								
							})
							.catch((err)=>{
								res.json({
									res_code: 0,
									res_error: err,
									res_body: {}
								});								
							});
		
	}		
};
module.exports = StaffService;
